package org.springperu.aop.demo.dao.jdbc;

import java.util.List;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springperu.aop.demo.dao.CustomerDao;
import org.springperu.aop.demo.model.Customer;


@Repository("customerDao")
public class CustomerDaoJdbc implements CustomerDao{
	public JdbcTemplate jdbcTemplate;
	
	@Autowired
	public void setDataSource(DataSource dataSource) {
		jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	
	public Customer getCustomer(Customer customer) {
		return jdbcTemplate.queryForObject("select * from customer",new Object[]{customer.getCustomerId()}, Customer.class);
	}
	
	public void saveCustomer(Customer customer) {
		jdbcTemplate.update("insert into customer(name) values (?)",customer.getName());
	}


	public List getAllCustomers() {
		return jdbcTemplate.queryForList("select customer_id as customerId, name as name from customer");
	}

}
